#ifndef _pwm_c__ruffi__eurobot08_
#define _pwm_c__ruffi__eurobot08_

#include <avr/io.h>

 /**********************
 ** pravy motor:     **
 **    - timer0      **
 **    - PB3 ( OC0 ) **
 **                  **
 ** levy motor:      **
 **    - timer2      **
 **    - PD7 ( OC2 ) **
 **                  **
 ** fast PWM mode    **
 ** prescaler 1*64   **
**********************/


/* inicializace casovacu */
void init_timer0_pwm ( void )
{
	DDRB |= (1<<PB3); /*set PB3 as output*/
	TCCR0 |= (1<<6) | (1<<3); /*fast PWM*/
	TCCR0 |= (1<<5); /*clear OC0 on compare match*/
	TCCR0 |= (1<<CS01) | (1<<CS00); /*prescaler 1/64*/
	OCR0 = 0; /*no duty cycle, set to do nothing*/
}

void init_timer2_pwm ( void )
{
	DDRD |= (1<<PD7); /*set PD7 as output*/
	TCCR2 |= (1<<6) | (1<<3); /*fast PWM*/
	TCCR2 |= (1<<5); /*clear OC2 on compare match*/
	TCCR2 |= (1<<CS21) | (1<<CS20); /*prescaler 1/64*/
	OCR2 = 0; /*no duty cycle, set to do nothing*/
}

/* nastaveni stridy / plneni */
/* 0 % 255                   */
void set_timer0_ratio ( int pct )
{
	if ( pct > 255 ) pct = 255;
	if ( pct < 0 ) pct = 0;
	OCR0 = pct;
}

void set_timer2_ratio ( int pct )
{
	if ( pct > 255 ) pct = 255;
	if ( pct < 0 ) pct = 0;
	OCR2 = pct;
}

#endif

